package com;

import com.fz.Test.Hello;
import com.fz.entity.Student;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by xiao zeng on 2017/7/1.
 */
public class Demo {
    protected BeanFactory factory;

    @Test
    public void sp() {
//        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicaionContext.xml");
        this.factory = new ClassPathXmlApplicationContext("applicationContext.xml");

        System.out.println(factory.getBean("h", Hello.class));

        Hello h1 = factory.getBean("h", Hello.class);
        Hello h2 = factory.getBean("h", Hello.class);
        System.out.println(h1 == h2);
        System.out.println(h1.sum(8));
    }

    @Test
    public void shows() {
        this.factory = new ClassPathXmlApplicationContext("applicationContext.xml");
        Hello h1 = this.factory.getBean("name", Hello.class);
        Hello h2 = this.factory.getBean("hh", Hello.class);
        h1.show();


    }

    @Test
    public void showH2() {
        this.factory = new ClassPathXmlApplicationContext("applicationContext.xml");
        Hello h2 = this.factory.getBean("hh", Hello.class);
        h2.show();

        System.out.println("集合");
        System.out.println(h2.getList().size());
        for (Student s : h2.getList()) {
            System.out.println(s.getName());
        }

        System.out.println("数组");
        System.out.println(h2.getStu().length);
        for (String ss : h2.getStu()) {
            System.out.println(ss);
        }
    }

    @Test
    public void sh(){
        this.factory = new ClassPathXmlApplicationContext("applicationContext.xml");
        SimpleDateFormat sd  = factory.getBean("dd",SimpleDateFormat.class);
        Date d = this.factory.getBean("d",Date.class);
        System.out.println(sd.format(d));
    }
}
